home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / library / utimes.c < prev    next >
C/C++ Source or Header  |  1996-03-13  |  3KB  |  95 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  utimes.c,v 1.1.1.1 1994/04/04 04:30:38 amiga Exp
  20.  *
  21.  *  utimes.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:38  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  26.  *  Initial revision
  27.  *
  28.  */
  29.  
  30. #define KERNEL
  31. #include "ixemul.h"
  32. #include "kprintf.h"
  33.  
  34. #if __GNUC__ != 2
  35. #define alloca __builtin_alloca
  36. #endif
  37.  
  38. static int
  39. __utimes_func (struct StandardPacket *sp, struct MsgPort *handler,
  40.                BPTR parent_lock,
  41.            BSTR name,
  42.            struct DateStamp *ds, int *no_error)
  43. {
  44.   sp->sp_Pkt.dp_Type = ACTION_SET_DATE;
  45.   sp->sp_Pkt.dp_Arg1 = 0;
  46.   sp->sp_Pkt.dp_Arg2 = parent_lock;
  47.   sp->sp_Pkt.dp_Arg3 = name;
  48.   sp->sp_Pkt.dp_Arg4 = (long)  ds;
  49.   
  50.   PutPacket (handler, sp);
  51.   __wait_sync_packet (sp);
  52.   *no_error = sp->sp_Pkt.dp_Res1 == -1;
  53.  
  54.   /* we want to set the date of the file pointed to, not that of the link */
  55.   return 1;
  56. }
  57.  
  58.  
  59. int
  60. utimes(char *name, struct timeval *tvp)
  61. {
  62.   struct DateStamp *ds;
  63.   struct timeval tv;
  64.   int result;
  65.   
  66.   if (!tvp)
  67.     /* in this case, fill in the current time */
  68.     syscall (SYS_gettimeofday, & tv, 0);
  69.   else
  70.     /* we have to ignore the value of "accesstime" and only
  71.      * look at "modificationtime", that's tvp[1] */
  72.     tv = tvp[1];
  73.  
  74.   tv.tv_sec -= ix_get_gmt_offset();
  75.   /* long-alignment here could be overkill, but with DOS you never know.. */
  76.   ds = alloca (sizeof (struct DateStamp) + 2);
  77.   ds = LONG_ALIGN (ds);
  78.  
  79.   ds->ds_Days   = tv.tv_sec / (24 * 60 * 60);
  80.   /* subtract unix/amigados time offset */
  81.   ds->ds_Days  -= 8*365+2;
  82.   tv.tv_sec    %= 24 * 60 * 60;
  83.   ds->ds_Minute = tv.tv_sec / 60;
  84.   tv.tv_sec    %= 60;
  85.   ds->ds_Tick   = (tv.tv_sec * TICKS_PER_SECOND +
  86.                (tv.tv_usec * TICKS_PER_SECOND)/1000000);
  87.  
  88.   result = __plock (name, __utimes_func, ds);
  89.  
  90.   if (! result) errno = __ioerr_to_errno (IoErr ());
  91.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  92.  
  93.   return result == -1 ? 0 : -1;
  94. }
  95.